

export default {
	data() {
		return {
			//维度
			dimensions:[],
			//度量
			measures:[],
			//参数
			params:[],
			//维度的父级子级的id
			parentid:'',
			childrenid:'',
			//度量的父级子级的id
			MRparentid:'',
			MRchildrenid:'',
			////参数的父级子级的Id
			paramsParentId:'',
			paramsId:'',
			//默认的标准字段
			defFields:[
				{fieldName:'ID_',comment:"主键",dataType:'varchar'},
				{fieldName:'TENANT_ID_',comment:'机构ID',dataType:'varchar'},
				{fieldName:'CREATE_BY_',comment:'创建人ID',dataType:'varchar'},
				{fieldName:'UPDATE_BY_',comment:'更新人ID',dataType:'varchar'},
				{fieldName:'CREATE_TIME_',comment:'创建时间',dataType:'datetime'},
				{fieldName:'UPDATE_TIME_',comment:'更新时间',dataType:'datetime'},
				{fieldName:'CREATE_DEP_ID_',comment:'创建部门ID',dataType:'varchar'},
				{fieldName:'CREATE_DEP_ID_',comment:'创建部门ID',dataType:'varchar'},
				{fieldName:'REF_ID_',comment:'外键',dataType:'varchar'},
				{fieldName:'PARENT_ID_',comment:'父ID',dataType:'varchar'},
				{fieldName:'UPDATE_VERSION_',comment:'版本号',dataType:'varchar'},
				{fieldName:'CREATE_BY_NAME',comment:'创建人名称',dataType:'varchar'},
				{fieldName:'UPDATE_BY_NAME',comment:'更新人名称',dataType:'varchar'},
				{fieldName:'COMPANY_ID_',comment:'公司ID',dataType:'varchar'},
				{fieldName:'INST_ID_',comment:'流程实例ID',dataType:'varchar'},
				{fieldName:'INST_STATUS_',comment:'流程实例状态',dataType:'varchar'},
				{fieldName:'DELETED_',comment:'逻辑删除',dataType:'varchar'},
                {fieldName:'USER_INFO_',comment:'用户信息',dataType:'varchar'},
			],
            //聚合函数
            aggregates:[
                {value:'COUNT',label:this.i18n('form.count', '计数')+"(COUNT)"},
                {value:'COUNTD',label:this.i18n('form.deCount', '去重计数')+"(COUNTD)"},
                {value:'SUM',label:this.i18n('form.sum', '求和')+"(SUM)"},
                {value:'AVG',label:this.i18n('form.average', '均值')+"(AVG)"},
                {value:'MAX',label:this.i18n('form.maxValue', '最大值')+"(MAX)"},
                {value:'MIN',label:this.i18n('form.minValue', '最小值')+"(MIN)"},
                {value:'NONE',label:this.i18n('form.not', '无')+"(NONE)"},
            ],
            //日期格式
            dateFormatList:[
                {value:'YYYY-MM-DD',label:"YYYY-MM-DD"},
                {value:'YYY-MM-DD HH:mm:ss',label:"YYY-MM-DD HH:mm:ss"},
                {value:'YYYY-MM-DD HH:mm',label:"YYYY-MM-DD HH:mm"},
                {value:'YYYY-MM-DD HH:mm:00',label:"YYY-MM-DD HH:mm:00"},
            ],
            //关联方式
            comparisonList:[
                {value:'EQ',label:this.i18n('form.equal', '等于')},
                {value:'NEQ',label:this.i18n('form.notEqual', '不等于')},
                {value:'IN',label:this.i18n('form.include', '包含')},
                {value:'LK',label:this.i18n('form.fuzzyMatch', '模糊匹配')},
                {value:'LEK',label:this.i18n('form.leftQuery', '左模糊查询')},
                {value:'RIK',label:this.i18n('form.rightQuery', '右模糊查询')},
            ],
            dateComparisonList:[
                {value:'EQ',label:this.i18n('form.equal', '等于')},
                {value:'NEQ',label:this.i18n('form.notEqual', '不等于')},
                {value:'LESS',label:this.i18n('form.lt', '小于')},
                {value:'LESS_EQUAL',label:this.i18n('form.le', '小于等于')},
                {value:'GREAT',label:this.i18n('form.gt', '大于') },
                {value:'GREAT_EQUAL',label:this.i18n('form.ge', '大于等于') },
                {value:'BETWEEN',label:this.i18n('form.between', '之间')},
            ],
		}
	},
	methods:{
		i18n(name,text,key){
			return this.$ti18(name,text,"screenLang",key);
		},
		/**
		 * 全部取消隐藏
		 * @param type 维度(dimension)/度量(measure)
		 */
		unhideAll(type){
			let self=this;
			this.$confirm({
				title: this.i18n("msa.unhideMsa","确定要全部隐藏/取消隐藏吗?"),
				okText: this.$ti18('rxForm.ackBtn','确认'),
				cancelText: this.$ti18('rxForm.cancelBtn','取消'),
				zIndex:99999,
				onOk() {
					for (let i = 0; i < self.checkboxList.length; i++) {
						let obj=self.checkboxList[i];
						if(obj.type==type){
							self.hideField(obj.index,obj.index1,obj.type,null);
						}
					}
					self.$forceUpdate();
				},
				onCancel() {},
			});
		},
		//数据模型的鼠标移入移出事件
		mouseenter(index,index1, type) {
			if (type == "dimension") {
				this.parentid = index;
				this.childrenid =index1;
			} else if (type == "measure") {
				this.MRparentid = index;
				this.MRchildrenid = index1;
			}else if (type == "param") {
				this.paramsParentId = index;
				this.paramsId = index1;
			}
		},
		mouseleave(type) {
			if (type == "dimension") {
				this.parentid = null;
				this.childrenid = null;
			} else if (type == "measure") {
				this.MRparentid = null;
				this.MRchildrenid = null;
			}else if (type == "param") {
				this.paramsParentid = null;
				this.paramsId = null;
			}
		},
		//切换到目标处 target:目标
		switchTo(index,index1, target) {
			//切换到维度
			if (target == "dimension") {
				let measure = this.measures[index].fields[index1];
				measure["dataFormat"] = "YYYY-MM-DD";
				delete measure.aggregate;
				this.dimensions[index].fields.push(measure);
				this.measures[index].fields.splice(index1, 1);
			}
			//切换到度量
			else if (target == "measure") {
				let dimension = this.dimensions[index].fields[index1];
				dimension["aggregate"] = "SUM";
				delete dimension.dataFormat;
				this.measures[index].fields.push(dimension);
				this.dimensions[index].fields.splice(index1, 1);
			}
		},
		addParam(index,index1, type){
			let obj={}
			if (type == "dimension") {
				obj = this.dimensions[index];
			}else if(type == "measure") {
				obj = this.measures[index];
			}
			let field = obj.fields[index1];
			let findParam = this.params.find((item) =>item.tableName== obj.tableName);
			if(findParam){
				let findField =  findParam.fields.find((item) =>item.fieldName== field.fieldName);
				if(!findField){
					findParam.fields.push({
						fieldLabel: field.fieldLabel,
						fieldName: field.fieldName,
						icon: field.icon,
						dataType:field.dataType,
						comparison:"EQ"
					})
				}
			}else {
				this.params.push({
					tableName:obj.tableName,
					fields:[{
						fieldLabel: field.fieldLabel,
						fieldName: field.fieldName,
						icon: field.icon,
						dataType:field.dataType,
						comparison:"EQ"
					}]
				})
			}
		},
		//删除参数
		delParams(index,index1){
			this.params[index].fields.splice(index1, 1);
			if(this.params[index].fields.length==0){
				this.params.splice(index, 1);
			}
		},
		//设置数据格式
		setDataFormat(e, index,index1) {
			this.dimensions[index].fields[index1]["dataFormat"] = e;
		},
		/**
		 * 隐藏与取消隐藏
		 * @param index 表下标
		 * @param index1 字段下标
		 * @param type 维度(dimension)/度量(measure)
		 * @param value ture/false
		 */
		hideField(index,index1,type,value){
			let obj={}
			if (type == "dimension") {
				obj = this.dimensions[index];
			}else if(type == "measure") {
				obj = this.measures[index];
			}
			let field = obj.fields[index1];
			if(value==null){
				value=field.hide==true?false:true;
			}
			field.hide=value;
		},
		//选择聚合函数
		setAggregate(e, index,index1) {
			this.measures[index].fields[index1]["aggregate"] = e;
		},
		//设置比较方式
		setComparison(e,index,index1){
			this.params[index].fields[index1].comparison = e;
		},
        //格式选中的数据
        selectedKeys(name) {
            if (name != undefined) {
                let obj = [];
                obj.push(name);
                return obj
            }
        },
	}
}
